package com.my.swas.common.utils;


import cn.hutool.core.util.StrUtil;
import com.my.swas.common.utils.ehcache.EhcacheUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @Description:
 * @author: :MaYong
 * @Date: 2019/5/28 15:16
 */
@Component
public class CacheUtils {

    @Autowired
    RedisUtil redisUtil;

    public void setStr(String key, String value) {
        EhcacheUtils.getDefaultEhcache().put(key, value);
        redisUtil.set(key, value);
    }

    public String getStr(String key) {
        String str = EhcacheUtils.getDefaultEhcache().get(key);
        if (StrUtil.isNotBlank(str)) {
            Object obj = redisUtil.get(key);
            if(!Objects.isNull(obj)){
                str = String.valueOf(obj);
            }
        }
        return str;
    }

    public void remove(String key) {
        EhcacheUtils.getDefaultEhcache().remove(key);
        redisUtil.delete(key);
    }

}
